<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    [#include "/common/common.ftl"]
</head>
<body>

<div class="demoTable">
    用户名：
    <div class="layui-inline">
        <input class="layui-input" name="userName" id="Main_userName" autocomplete="off">
    </div>
    Email：
    <div class="layui-inline">
        <input class="layui-input" name="email" id="Main_email" autocomplete="off">
    </div>
    <button class="layui-btn" data-type="reload">查询</button>
</div>

<table class="layui-hide" id="main_table_user" lay-filter="user"></table>

<script>
    layui.use('table', function(){
        var table = layui.table;

        //方法级渲染
        table.render({
            elem: '#main_table_user'
            ,url: '${base}/user/list'
            ,cols: [[
                {checkbox: true, fixed: true}
                ,{field:'id', title: 'ID', width:80, sort: true, fixed: true}
                ,{field:'username', title: '用户名', width:80}
                ,{field:'sex', title: '性别', width:80, sort: true}
                ,{field:'city', title: '城市', width:80}
                ,{field:'sign', title: '签名'}
                ,{field:'experience', title: '积分', sort: true, width:80}
                ,{field:'score', title: '评分', sort: true, width:80}
                ,{field:'classify', title: '职业', width:80}
                ,{field:'wealth', title: '财富', sort: true, width:135}
            ]]
            ,id: 'mainUserReload'
            ,page: true
            ,height: 315
            ,request: {
                pageName: 'pageNum' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "data": res.list //解析数据列表
                };
            }
        });

        var $ = layui.$, active = {
            reload: function(){
                var Main_userName = $('#Main_userName');

                //执行重载
                table.reload('mainUserReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        key: {
                            userName: Main_userName.val()
                        }
                    }
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>

</body>
</html>